package demo6;

import java.lang.reflect.Array;
import java.util.Arrays;

class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return this.name.compareTo(o.name);
    }

}
public class Test {
    public static void main(String[] args) {
        Student student1 = new Student("zhangsan",9);
        Student student2 = new Student("lisi",160);
        AgeComparator ageComparator = new AgeComparator();
        NameComparator nameComparator = new NameComparator();
        System.out.println(ageComparator.compare(student1, student2));
        System.out.println(nameComparator.compare(student1,student2));


        Student student[] = {
                new Student("lisi",8),new Student("zhangsan",9),new Student("miao",18)
        };
        Arrays.sort(student,ageComparator);
    }
    public static void main1(String[] args) {
        /*Student student1 = new Student("zhangsan",9);
        Student student2 = new Student("lisi",19);
        System.out.println(student1.compareTo(student2));*/
        Student student[] = {
                new Student("lisi",8),new Student("zhangsan",9),new Student("miao",18)
        };
        Arrays.sort(student);
        System.out.println(Arrays.toString(student));
    }

}
